


package yf.mall.controller.app;
import com.yf.request.SearchParam;
import java.io.IOException;
import java.util.List;
import com.yf.response.RRException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import yf.mall.vo.AppConfigVo;
import yf.mall.service.app.AppConfigService;
import com.yf.response.R;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import org.springframework.web.multipart.MultipartFile;
                

@RestController
@RequestMapping("/app/config")
public class AppConfigController {
    @Autowired
    private AppConfigService appConfigService;

    @RequestMapping("/list")
    @RequiresPermissions("app:config:list")
    public R list(@RequestBody SearchParam<AppConfigVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<AppConfigVo> list = appConfigService.findVo(params.getEntity());
        return R.ok(new PageInfo(list));
    }

    @RequestMapping("/down")
    @RequiresPermissions("app:config:list")
    public void down(@RequestBody SearchParam<AppConfigVo> params, HttpServletResponse response) {
        List<AppConfigVo> list = appConfigService.findVo(params.getEntity());
            appConfigService.downLoad(response, list);
    }


    @RequestMapping("/upload")
    public void upload(MultipartFile file) {
        try {
                appConfigService.upload(file.getInputStream());
        } catch (IOException e) {
            throw new RRException("上传的文件有误!");
        }
    }


    @RequestMapping("/info/{id}")
    @RequiresPermissions("app:config:info")
    public R info(@PathVariable("id") Long id) {
            AppConfigVo vo = appConfigService.getVo(id);

        return R.ok(vo);
    }

    @RequestMapping("/save")
    @RequiresPermissions("app:config:save")
    public R save(@RequestBody AppConfigVo vo) {
            appConfigService.saveVo(vo);
        return R.ok(vo);
    }

    @RequestMapping("/update")
    @RequiresPermissions("app:config:update")
    public R update(@RequestBody AppConfigVo vo) {
            appConfigService.updateVo(vo);

        return R.ok(vo);
    }

    @RequestMapping("/delete")
    @RequiresPermissions("app:config:delete")
    public R delete(Long[]ids) {
            appConfigService.deleteBatch(ids);

        return R.ok();
    }

    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order!=null ? order : "id desc");
        List<AppConfigVo> list = appConfigService.findVo(null);
        return R.ok(list);
    }

    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
                                                                                                return R.ok(options);
    }


}
